

#if !defined(COCO_PARSER_H__)
#define COCO_PARSER_H__

#include<map>
#include<string>
#include<iostream>
#include<vector>
#include "sqlFunc.h"
using namespace std;


#include "Scanner.h"



class Errors {
public:
	int count;			// number of errors detected

	Errors();
	void SynErr(int line, int col, int n);
	void Error(int line, int col, const wchar_t *s);
	void Warning(int line, int col, const wchar_t *s);
	void Warning(const wchar_t *s);
	void Exception(const wchar_t *s);

}; // Errors

class Parser {
private:
	enum {
		_EOF=0,
		_c=1,
		_const=2,
		_num=3,
		_rel=4,
	};
	int maxT;

	Token *dummyToken;
	int errDist;
	int minErrDist;

	void SynErr(int n);
	void Get();
	void Expect(int n);
	bool StartOf(int s);
	void ExpectWeak(int n, int follow);
	bool WeakSeparator(int n, int syFol, int repFol);

public:
	Scanner *scanner;
	Errors  *errors;

	Token *t;			// last recognized token
	Token *la;			// lookahead token

int flagg;


	Parser(Scanner *scanner);
	~Parser();
	void SemErr(const wchar_t* msg);

	void Sql();
	void Modify_data();
	void Define_data();
	void Create_command(vector<ckval> &a, string &table );
	void Select_command();
	void Insert_command();
	void Update_command();
	void Delete_command();
	void Drop_command();
	void str(string & xz);
	void Name_type_pair(vector<ckval> &a);
	void type(string & type);
	void number(string &a);
	void str_list(vector<string> &list);
	void Condition(vector<int> &condition,vector<string> &a,vector<string> &b,vector<string> &c ,int &count);
	void key_value(map<string,string> &col_table);
	void strconst(string & xz);
	void strconst_list(vector<string> &list);
	void number_list(vector<string> &list);
	void con(vector<int> &x,vector<string> &a,vector<string> &b,vector<string> &c ,int &count);
	void r_list(vector<string> &list);
	void r(string &ab);

	void Parse();

}; // end Parser



#endif // !defined(COCO_PARSER_H__)

